package com.example.webcomen.Websocket;

import cn.hutool.json.JSONObject;
import cn.hutool.log.Log;
import com.example.webcomen.Common.AjaxResult;
import com.google.gson.Gson;

import javax.websocket.EncodeException;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;
import java.util.HashMap;

public class WebSocketEncoder  implements Encoder.Text<HashMap> {
    private static Gson gson=new Gson();
    private static Log log=Log.get("info");
    @Override
    public String encode(HashMap hashMap) throws EncodeException {
        try {
            return gson.toJson(hashMap);
        }catch (Exception e){
            log.info(e);
        }
        return null;
    }

    @Override
    public void init(EndpointConfig endpointConfig) {

    }

    @Override
    public void destroy() {

    }
}
